package config.Strategy;

import com.baomidou.mybatisplus.generator.config.builder.Controller;
import config.Config;
import org.apache.commons.lang3.StringUtils;

/**
 * @Description config.Strategy
 * @Author zhengzetao
 * @Date 2022/9/18 18:33
 */
public class ControllerConfig extends Config {

    final private static String GROUP = "StrategyConfig.Controller";

    //superClass(String)	设置父类	com.baomidou.global.BaseController
    private String superClass;
    //enableHyphenStyle	开启驼峰转连字符	默认值:false
    private boolean enableHyphenStyle;
    //enableRestStyle	开启生成@RestController 控制器	默认值:false
    private boolean enableRestStyle;
    //formatFileName(String)	格式化文件名称 %sAction
    private String formatFileName;

    private ControllerConfig() {
        super(GROUP);
        this.superClass = getStr("superClass");
        this.enableHyphenStyle = getBool("enableHyphenStyle", false);
        this.enableRestStyle = getBool("enableRestStyle", false);
        this.formatFileName = getStr("formatFileName");
    }

    public static void setting(Controller.Builder builder) {
        ControllerConfig config = new ControllerConfig();
        if(StringUtils.isNotBlank(config.superClass)){
            builder.superClass(config.superClass);
        }
        if(config.enableHyphenStyle){
            builder.enableHyphenStyle();
        }
        if(config.enableRestStyle){
            builder.enableRestStyle();
        }
        if(StringUtils.isNotBlank(config.formatFileName)){
            builder.formatFileName(config.formatFileName);
        }
    }
}
